export NAME=ggSpamFree

svn up

export V=$((`svn info | grep Revision | sed s/Revision:\ //`+1))
export VERSION=\"'1.2.'`printf "%i.%i" $(($V/10)) $(($V%10))`\"

echo Building version $VERSION

cat stopwords.txt | sed  s/..*/,\'\\0\'/  > stopwords.js;

export OPTS="-DVERSION=$VERSION"

# the "header" file is a docblock comment for user script. 
# Save it from the preprocessor.
cat $NAME.h.js   \
| sed s/'$VERSION'/$VERSION/g   \
> install/$NAME.user.js

# as user script
cat $NAME.js | sed s/^\\s*\\/\\/#/#/  \
| cpp $OPTS -DEXT_USER=1    \
| sed s/^[#:\<].*//  \
>> install/$NAME.user.js

# as chromium extension
export TGT_CHROME=install/chromium/$NAME.min.js
echo '/** ggSpamFree chrome extension */'  > $TGT_CHROME
cat $NAME.js | sed s/^\\s*\\/\\/#/#/  \
| cpp $OPTS -DEXT_CHROME=1 \
| sed s/^[#:\<].*// \
>> $TGT_CHROME

cat install/chromium/manifest.h.js   \
| sed s/'$VERSION'/$VERSION/g   \
> install/chromium/manifest.json

# build chrome extension
chromium-browser --pack-extension=install/chromium --pack-extension-key=install/chromium.pem 

rm ggSpamFree.zip

# zip everything up
cd install/chromium
zip -r ../../ggSpamFree.zip .  -x *.svn*

